// pages/login/index.js
// Page({
//   handleGetUserInfo(e) {
//     // console.log(e);
//     const {userInfo} = e.detail
//     wx.setStorageSync('userInfo', userInfo)
//     wx.navigateBack({
//       delta: 1,
//     })
//   }
// })
const app = getApp()
const db = wx.cloud.database({
  env:'xiaochengxu-2gcm02cv74f2b2b8'
})
const userList = db.collection("userList")
Page({
  data:{
    phone:'',
    password:''
  },
  phoneInput: function (e) {
    this.setData({
    phone: e.detail.value
    })
    },
    passwordInput: function (e) {
      this.setData({
      password: e.detail.value
      })
    },
    login() {
      let that=this
      let {phone,password} =this.data 
      userList.where({
        phone:phone,
        password:password,
      })
      .get({
        success(res) {
          console.log(res);
          if(res.data.length===0) {
            wx.showToast({
              title: '号码或密码错误',
              icon:'none'
            })
          } else {
            wx.showToast({
              title: '登录成功',
              icon:'none',
               duration:2000
            })
            wx.cloud.callFunction({
              name:'getopenid',
              success(res) {
                // console.log(res);
                wx.setStorageSync('openid', res.result.openid)
              }
            })
            setTimeout(function(){
              wx.switchTab({
                url: '/pages/index/index',
              })
            },2000)
          }
        }
      })
    },
    gotoregister() {
      wx.navigateTo({
        url: '/pages/register/register',
      })
    }
})